package com.twu.biblioteca.model;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by davecroman on 11/09/2014.
 */
public class Book extends BorrowableAsset implements Comparable<Book>{

    private static AtomicInteger idGenerator = new AtomicInteger();

    private String name;
    private String author;
    private String publisher;

    private Integer id;

    /**
     * Generate a book with the specified details.
     * @param name
     * @param author
     * @param publisher
     */
    public Book(String name, String author, String publisher){
        this.name = name;
        this.author = author;
        this.publisher = publisher;
        this.id = idGenerator.incrementAndGet();
    }

    public String toString(){
        return String.format("[%d] %-25s | %-25s | %-25s", id, name, author, publisher);
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getPublisher(){
        return publisher;
    }

    public String getAuthor(){
        return author;
    }

    @Override
    public int compareTo(Book book) {
        return name.compareTo(book.getName());
    }
}
